package edu.whut.jdk7.calendar;
/*
    Calendar c = Calendar.getInstance();//获取当前时间
    int year = c.get(Calendar.YEAR) 获取字段信息
    c.set(Calendar.YEAR，2028) 修改字段信息,可以修改某个字段，也可以很多字段
    c.add(Calendar.YEAR，2) 对某个字段增加或较少

    将Date对象转换Calendar时间对象
    Calendar c = Calendar.getInstance();
    c.setTime(date);

    根据Calendar得到Date对象
    Date date1 = c.getTime();


 */
import java.util.Calendar;

public class CalendarDemo01 {
    public static void main(String[] args) {

    }

    private static void addMethod() {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR,2);
        System.out.println(c.get(Calendar.YEAR));
    }

    private static void setMethod() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR,1999);
        System.out.println(c.get(Calendar.YEAR)+"年");
        c.set(1949,8,19);
        System.out.println(c.get(Calendar.YEAR)+"年");
    }

    private static void getMethod() {
        Calendar c = Calendar.getInstance();
        System.out.println(c);
        int year = c.get(Calendar.YEAR);//年
        int mouth = c.get(Calendar.MONTH)+1;//月，0-11，结果需要自己加1
        int day = c.get(Calendar.DAY_OF_MONTH);

        int week = c.get(Calendar.DAY_OF_WEEK);//星期，从日开始是1，星期六是7
        char[] weeks = {' ','日','一','二','三','四','五','六'};
        //                   1    2     3   4    5    6    7

        System.out.println(year+"年"+mouth+"月"+day+"日 星期"+weeks[week]);


    }
}
